// Copyright (c) MatrixFramework. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;

namespace MatrixFramework.Core.Results;

/// <summary>
/// 操作结果类
/// </summary>
public class Result : ResultBase
{
    /// <summary>
    /// 是否失败
    /// </summary>
    public bool IsFailure => !IsSuccess;
    /// <summary>
    /// 私有构造函数
    /// </summary>
    private Result() { }

    /// <summary>
    /// 创建成功结果
    /// </summary>
    /// <returns>成功结果</returns>
    public static Result Success()
    {
        return new Result { IsSuccess = true };
    }

    /// <summary>
    /// 创建失败结果
    /// </summary>
    /// <param name="error">错误信息</param>
    /// <returns>失败结果</returns>
    public static Result Failure(string error)
    {
        var result = new Result { IsSuccess = false };
        result.AddError(error);
        return result;
    }

    /// <summary>
    /// 创建失败结果
    /// </summary>
    /// <param name="errors">错误信息列表</param>
    /// <returns>失败结果</returns>
    public static Result Failure(IEnumerable<string> errors)
    {
        var result = new Result { IsSuccess = false };
        result.AddErrors(errors ?? new List<string>());
        return result;
    }

    /// <summary>
    /// 创建失败结果
    /// </summary>
    /// <param name="error">错误信息</param>
    /// <returns>失败结果</returns>
    public new static Result Error(string error)
    {
        return Failure(error);
    }
}